package com.gxks.lhs.controller.admin;


import com.gxks.lhs.constants.R;
import com.gxks.lhs.entity.Admin;
import com.gxks.lhs.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author LuoHaisong
 * @since 2023-05-19
 */


@Api(tags = "管理员模块")
@Slf4j
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @ApiOperation("管理员登录接口")
    @PostMapping("/login")
    public R login(@RequestBody Admin admin) {
        boolean login = adminService.login(admin.getUsername(), admin.getPassword());

        if (login) {
            return R.success();
        }
        return R.error();
    }

    @ApiOperation("根据用户名获取用户信息")
    @RequestMapping
    public R getAdminByUsername(String username) {
        Admin admin = adminService.selectByUsername(username);
        if (admin != null) {
            return R.success(admin);
        }
        return R.error();
    }

    @ApiOperation("管理员更新个人信息模块")
    @PutMapping("/update")
    public R update(@RequestBody Admin admin) {
        boolean update = adminService.update(admin);
        if (update) {
            return R.success();
        }
        return R.error();
    }
}

